//Kontrollerin client side tutarli veri girisini saglamasi icin kullanacagi client side metodlar
//15.09.2005 tamer.oz Initial Creation


//Basilan tusun numeric bir degere ait olup olmadigini kontrol eder.
function validateNumericBox()
{
    if (!(event.keyCode>=48 && event.keyCode<=57))
	{
		return false;
	}
}

function validateDecimalBox()
{
    if (!((event.keyCode>=48 && event.keyCode<=57) || event.keyCode ==44 ))
	{
		return false;
	}
}

//Basilan tusun numeric olmayan bir degere ait olup olmadiigni kontrol eder.
function validateStringBox()
{
    if (event.keyCode>=48 && event.keyCode<=57)
	{
		return false;
	}
}
function validateDatePickerKeyUp()
{
    if (!(event.keyCode == 8))
    {
	    if (event.srcElement.value.length == 2 || event.srcElement.value.length == 5)
	    {
		    event.srcElement.value+="/";
	    }
    }   
}
function validateDatePickerKeyDown(ipt)
{
    if (event.keyCode==27)
    {
        ToggleCalendar(event,ipt);
    } 
}
function validateDatePickerKeyPress()
{
    if (event.srcElement.value.length>=10)
    {
        return false;
    }
	if (!(event.keyCode>=48 && event.keyCode<=57))
	{
		return false;
	}
}
function FormatNum(thisis,dig) {	
	var tempstr,newstr,str;
	var commapos,aftercomma;
	str = thisis.value;
	str = StrToMoney(str);	
	var mantissa = new String();	
	var tmp = new String();
	tmp = str;			
	if (tmp.indexOf(",",0)>0) {
		str = tmp.substring(0,tmp.indexOf(",",0))
		mantissa = tmp.substring(tmp.indexOf(",",0),tmp.length)
	}

	var output
	commapos=str.indexOf(";");
	if (commapos>=0) {
		aftercomma=str.substr(commapos);
		str=str.substr(0,commapos);
	}
	else aftercomma="";
	if (mantissa.length>dig)
	{
	    mantissa=mantissa.substring(0,dig+1);
	}
	if (str.length > 3) {
		tempstr=str;
		newstr="";
		while (tempstr.length>3)
		{
			newstr="."+tempstr.substr(tempstr.length-3)+newstr; 
			tempstr=tempstr.substr(0,tempstr.length-3);
		}		
		output = tempstr+newstr+aftercomma;
		if (mantissa.length>0) output+= mantissa;
		thisis.value = output;
	}
	else
	{
		str		= str.replace('.','');
		output	= str;
		if (mantissa.length>0) output+= mantissa;
		thisis.value = output;
	}
	return true;
}
function StrToMoney(currency) {	
	var num = new String();
	num = currency;
	while (num.indexOf('.',0)>0) {
		num = num.replace('.','');
	}
	return num;
}


var	ie=document.all
function hideElement( elmID, overDiv )
{
if( ie )
{
for( i = 0; i < document.all.tags( elmID ).length; i++ )
{
obj = document.all.tags( elmID )[i];
if( !obj || !obj.offsetParent )
{
continue;
}

// Find the element's offsetTop and offsetLeft relative to the BODY tag.
objLeft   = obj.offsetLeft;
objTop    = obj.offsetTop;
objParent = obj.offsetParent;

while( objParent.tagName.toUpperCase() != "BODY" )
{
objLeft  += objParent.offsetLeft;
objTop   += objParent.offsetTop;
objParent = objParent.offsetParent;
}

objHeight = obj.offsetHeight;
objWidth = obj.offsetWidth;

if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
else if( overDiv.offsetTop >= ( objTop + objHeight ));
else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
else
{
obj.style.visibility = "hidden";
}
}
}
}

/*
* unhides <select> and <applet> objects (for IE only)
*/
function showElement( elmID )
{
if( ie )
{
for( i = 0; i < document.all.tags( elmID ).length; i++ )
{
obj = document.all.tags( elmID )[i];

if( !obj || !obj.offsetParent )
{
continue;
}

obj.style.visibility = "";
}
}
}

function HolidayRec (d, m, y, desc)
{
this.d = d
this.m = m
this.y = y
this.desc = desc
}
function controlFocus(ctrl)
{
ctrl.className='controlFocus'
}
function controlOnMouseOut(ctrl)
{
if (ctrl.className!='controlFocus') {ctrl.className='controlNormal';}
}
function controlOnMouseOver(ctrl)
{
if (ctrl.className!='controlFocus') {ctrl.className='controlOver';}
}
function controlOnBlur(ctrl)
{
ctrl.className='controlNormal';
}
function OpenFileUpload(ctrlLink,ctrlName)
{
    val = window.showModalDialog('/Utils/FileBrowser.aspx?Path=~/content/Files/', '', 'dialogWidth:700px;dialogHeight:450px;'); 
    if(val!=undefined)
    {
        str=val.split("|");
        document.getElementById(ctrlLink).value = str[0];
        document.getElementById(ctrlName).value = str[1];
    }
}
function OpenPictureUpload(ctrlLink,ctrlName)
{
    val = window.showModalDialog('/Utils/ImageGallery.aspx?Path=~/content/Photos/', '', 'dialogWidth:700px;dialogHeight:450px;'); 
    if(val!=undefined)
    {
        str=val.split("|");
        document.getElementById(ctrlLink).value = str[0];
//        document.getElementById(ctrlName).value = str[1];
    }
}
function OpenFileUploadEditor(ctrl,fd)
{

    val = window.showModalDialog('/Utils/FileBrowser.aspx?Path=' + fd, '', 'dialogWidth:700px;dialogHeight:450px;'); 
    if(val!=undefined)
    {
        str=val.split("|");
        document.getElementById(ctrl + 'editorClient').value += "<a href='" +  str[0] + "'>" + str[1] + "(" + str[2] + "kb)</a>";
        document.getElementById(ctrl + 'editor').innerHTML=document.getElementById(ctrl + 'editorClient').value
    }
}
function OpenImageEditor(ctrl,fd)
{
    val = window.showModalDialog('/Utils/ImageGallery.aspx?Path=' + fd, '', 'dialogWidth:700px;dialogHeight:450px;'); 
    if(val!=undefined)
    {
        str=val.split("|");
        //document.getElementById(ctrl + 'editorClient').value += "<img src='" +  str[0] + "' width='" + str[1] + "' height='" + str[2] + "'>";
        document.getElementById(ctrl + 'editorClient').value += "<img src='" +  str[0] + "'>";
        document.getElementById(ctrl + 'editor').innerHTML=document.getElementById(ctrl + 'editorClient').value
    }
}
function OpenPhoto(fd)
{
    val = window.showModalDialog('/Utils/Photos.aspx?Photo=' + fd, '', 'dialogWidth:700px;dialogHeight:700px;'); 
}


	function callFormatting(c,formatstring)
	{
		c.execCommand(formatstring);
		return  false;
	}
	function clearDocument()
	{
		return  false;
	}
	function changeFont(e)
	{
		document.execCommand('FontName', false, e.value);
		return  false;
	}
	function changeFontSize(e)
	{
		document.execCommand('FontSize', false, e.value);
		return  false;
	}
	function changeFontColor(e)
	{
		document.execCommand('ForeColor', false, e.value);
		return  false;
	}
	function changeBackColor(e)
	{
		document.execCommand('BackColor', false, e.value);
		return  false;
	}
    function SetPanel(targetControlString,controlString)
    {
        targetControl=document.getElementById(targetControlString);
        control=document.getElementById(controlString);
       if(targetControl.style.visibility=='visible')
       {
            targetControl.style.visibility='hidden';
            targetControl.style.display='none';
            control.src="/images/pnlExpand.jpg"
       }
       else
       {
            targetControl.style.visibility='visible';
            targetControl.style.display='block';
            control.src="/images/pnlCollapse.jpg"
       }
    }